import type { IUploadFileRes001, IUploadFileRes002, IUploadFile005Req, IUploadFile005Res } from './file-upload.d';

/**
 * @description: 上传文件
 */
export function uploadFile001(params: { fileTpCd: string }, file: File | Blob): Promise<IUploadFileRes001> {
  const formData = new FormData();
  formData.append('fileTpCd', params.fileTpCd);
  formData.append('file', file);

  return window.$request({
    url: '/bmpfl/file/upload/001',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data;charset=UTF-8'
    },
    data: formData
  });
}
/**
 * @description: 批量上传文件
 */
export function uploadFile002(params: { fileTpCd: string; fileCgyId: string }, files: FileList | File[]): Promise<IUploadFileRes002> {
  const formData = new FormData();
  formData.append('fileTpCd', params.fileTpCd);
  formData.append('fileCgyId', params.fileCgyId);
  for (const item of files) {
    formData.append('fileList', item);
  }

  return window.$request({
    url: '/bmpfl/file/upload/002',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data;charset=UTF-8'
    },
    data: formData
  });
}

/**
 * @description: 文件上传（提供远程图片地址，后端下载保存后返回对象存储地址）
 */
export function uploadFile005(params: IUploadFile005Req): Promise<IUploadFile005Res> {
  return window.$request.post('/bmpfl/file/upload/005', params);
}
